package com.ruoyi.web.controller.memberManagement;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MemberPointsRule;
import com.ruoyi.system.service.IMemberPointsRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员积分规则（存储各门店的积分获取与抵现规则）Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Api(tags="会员积分规则")
@RestController
@RequestMapping("/system/memberPointsRule")
public class MemberPointsRuleController extends BaseController
{
    @Autowired
    private IMemberPointsRuleService memberPointsRuleService;

    /**
     * 查询会员积分规则列表
     */
    @ApiOperation("查询会员积分规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<MemberPointsRule> list = memberPointsRuleService.selectMemberPointsRuleListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出会员积分规则
     */
    @ApiOperation("导出会员积分规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "会员积分规则（存储各门店的积分获取与抵现规则）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<MemberPointsRule> list = memberPointsRuleService.selectMemberPointsRuleListByName(storeName);
        ExcelUtil<MemberPointsRule> util = new ExcelUtil<MemberPointsRule>(MemberPointsRule.class);
        util.exportExcel(response, list, "会员积分规则（存储各门店的积分获取与抵现规则）数据");
    }

    /**
     * 获取会员积分规则详细信息
     */
    @ApiOperation("获取会员积分规则详细信息")
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(memberPointsRuleService.selectMemberPointsRuleById(id));
    }

    /**
     * 新增会员积分规则列表
     */
    @ApiOperation("新增会员积分规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "会员积分规则（存储各门店的积分获取与抵现规则）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberPointsRule memberPointsRule)
    {
        return toAjax(memberPointsRuleService.insertMemberPointsRule(memberPointsRule));
    }

    /**
     * 修改会员积分规则列表
     */
    @ApiOperation("修改会员积分规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "会员积分规则（存储各门店的积分获取与抵现规则）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberPointsRule memberPointsRule)
    {
        return toAjax(memberPointsRuleService.updateMemberPointsRule(memberPointsRule));
    }

    /**
     * 删除会员积分规则列表
     */
    @ApiOperation("删除会员积分规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "会员积分规则（存储各门店的积分获取与抵现规则）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberPointsRuleService.deleteMemberPointsRuleByIds(ids));
    }
}
